﻿/// <reference path="../../Scripts/jquery-1.5.1.js" />

function dclick() {
    $('#hotcityhintDiv').hide();
    $('#CalFrame').hide();
    $('#cgbk6').hide();
    $("#xue_OrderLine_Origin").hide();
    $("#xue_OrderLine_Dest").hide();
    $("#xue_Hotel").hide();
    $("#xue_Tickets_Origin").hide();
    $("#xue_Tickets_Dest").hide();
    $("#xue_FindScenic").hide();
    $("#Search_Synthesize_Div").hide();
    $("#xue_Djxl_Mdd").hide();
}
var oi = 1, tt, isok = true;
var nobj, iobj, dobj;
$(document).ready(function () {
    $("li[id^=cgzwmenu]").click(function () {
        var _this = $(this);
        var index = _this.attr("id").replace("cgzwmenu", "");
        return cgzwshow(index);
    });

    $(".searchf2 input:submit").removeAttr("disabled").click(function () {
        return checkForm();
    });

    $("#txtStartCityName").focus(function () {
        $("#xue_OrderLine_Dest").remove();
    });

    $(".searchf2 input:text ").click(function () {
        var _this = $(this);
        nobj = _this;
        iobj = $("#" + _this.attr("hid"));
        dobj = $("#" + _this.attr("hdepth"));
        dclick();
        if (_this.attr("default") == "CalFrame") {
            showCal(_this.attr("id"), '', false, $.trim(_this.attr("method")), 6, -19);
        }
        else {
            if ($("#" + _this.attr("default")).length == 0 && isok) {
                var selectattr = _this.attr("default");
                var arr = window[_this.attr("default")];
                if (selectattr != 'xue_OrderLine_Dest') {
                    var div = $("<div id=\"" + _this.attr("default") + "\" class=\"city_divtc\" style=\"display:none;\"></div>");
                    $.each(arr, function (i) {
                        $("<div class=\"city_divtc_t\">" + (i == 0 ? "<a class=\"closex\"></a>" : "") + "<span>" + arr[i].name + "</span></div><div class=\"city_divtc_m\"><ul></ul></div>").appendTo(div);
                        var ul = div.find("ul").eq(i);
                        if (_this.attr("default") == "Search_Synthesize_Div") {
                            $.each(arr[i].value, function (j) {
                                $("<li><a title=\"" + arr[i].value[j].name + "\" target=\"_blank\" href=\"" + arr[i].value[j].depth + "\">" + arr[i].value[j].name + "</a></li>").appendTo(ul);
                            });
                        }
                        else {
                            $.each(arr[i].value, function (j) {
                                $("<li><a style=\"cursor:pointer;\" title=\"" + arr[i].value[j].name + "\" method=\"default\" deffer=\"" + arr[i].value[j].id + "\" depth=\"" + arr[i].value[j].depth + "\">" + arr[i].value[j].name + "</a></li>").appendTo(ul);
                            });
                        }
                    });
                    if (_this.attr("default") != "Search_Synthesize_Div") {
                        div.bind("click", function (event) {
                            var _this = $(event.target).closest("a");
                            if(_this.length==1 && !_this.hasClass("closex")){
                            var id = _this.attr("deffer"), name = _this.attr("title"), depth = _this.attr("depth");
                            fillOption(name, id, depth);
                            }
                        });
                    }
                    if (_this.attr("class") == "inp-pic") {
                        $(".searchf2").append(div);
                    }
                    else {
                        $(".searchf2").after(div);
                    }
                }
                else {
                    var ssite = $("#hscity").val();
                    if (ssite == '') {
                        ssite = '1020';
                    }
                    isok = false;
                    showCommonOsiteCity(ssite, _this);

                }
            }
            fun_displayObj(_this, _this.attr("default"), -25, 8);
        }
        return false;
    }).focusin(function () {
        var _this = $(this);
        var method = _this.attr("method");
        if (method != "date" && _this.attr("value") == _this.attr("tips"))
            _this.attr("value", "");
        _this.trigger("click");
        return false;
    }).focusout(function (event) {
        var _this = $(this);
        var msg = _this.attr("tips");
        if ($.trim(iobj.attr("value")) == "" && !$('#hotcityhintDiv').is(':hidden')) {
            var li = $("#scity").children("li.onhover");
            var $elem = li.length == 1 ? li : $("#scity").children("li").eq(0);
            var id = $elem.attr("deffer"), name = $elem.attr("title"), depth = $elem.attr("depth");
            fillOption(name, id, depth);
        }
        if ($.trim(_this.val()) == "") {
            _this.attr("value", msg);
        }
        return false;
    }).keyup(function (event) {
        if ($('#hotcityhintDiv').is(':hidden') && event.keyCode != 9) {
            dclick();
        }
        tt = $(this).attr("method");
        fillSelectOnkeyup($(this).attr('value'), 7, iobj.attr("id"), event);
        return false;
    }).each(function () {
        var _this = $(this);
        if (_this.attr("id") == "txthSdate") {
            _this.attr("value", showdate(1));
        }
        else if (_this.attr("id") == "txthEdate") {
            _this.attr("value", showdate(2));
        }
        else {
            _this.attr("value", _this.attr("tips"));
        }
    });

    $("#scity").mouseover(function (event) {
        $(this).children("li").removeClass('onhover');
        var $elem = $(event.target).closest("li");
        $elem.toggleClass('onhover');
        return false;
    });

    $("#cgbk6").mouseover(function (event) {
        $(this).children("a").removeClass('current');
        var $elem = $(event.target).closest("a");
        $elem.toggleClass('current');
    });

}).click(function () {
    dclick();
}).keydown(function (event) {
    if (event.keyCode == 13) {
        return false;
    }
});

function showCommonOsiteCity(ssite, _this) {
    $.getJSON("http://beijing.lotour.com/dujiaxianlu/api-AssociateCommonOsite", "sSite=" + escape($.trim(ssite)) + "&randID=" + escape(new Date()) + "&callback=?", function (data) {
        if (data.status == 0) {
            alert("没有信息。");
        }
        else {
            var arr = data.msg;
            var div = $("<div id=\"xue_OrderLine_Dest\" class=\"city_divtc\" style=\"display:none;\"></div>");
            $.each(arr, function (i) {
                $("<div class=\"city_divtc_t\">" + (i == 0 ? "<a class=\"closex\"></a>" : "") + "<span>" + arr[i].name + "</span></div><div class=\"city_divtc_m\"><ul></ul></div>").appendTo(div);
                var ul = div.find("ul").eq(i);

                $.each(arr[i].value, function (j) {
                    $("<li><a style=\"cursor:pointer;\" title=\"" + arr[i].value[j].name + "\" method=\"default\" deffer=\"" + arr[i].value[j].id + "\" depth=\"" + arr[i].value[j].depth + "\">" + arr[i].value[j].name.substring(0, 4) + "</a></li>").appendTo(ul);
                });
            });
            $(".searchf2").after(div);
            div.bind("click", function (event) {
                var _this = $(event.target).closest("a");
                var id = _this.attr("deffer"), name = _this.attr("title"), depth = _this.attr("depth");
                fillOption(name, id, depth);
            });
        }
        fun_displayObj(_this, _this.attr("default"), -25, 8);
        isok = true;
        return false;
    })
};

function cgzwshow(i) {
    $('#stys').html($("#cgzwmenu" + i).text());
    $('#cgbk' + oi).hide();
    $('#cgbk' + i).show();
    $("#subnav").slideUp('slow');
    oi = i;
    return false;
}

function LineSsiteInit() {

    var AreaName = $.cookie("IndexAreaName") + '出发';
    var cityId = $.cookie("CityID");
    $.getJSON("http://beijing.lotour.com/dujiaxianlu/api-TopCommonSearch", "sSite=" + cityId + "&randID=" + escape(new Date()) + "&callback=?", function (data) {
        if (data.status == 0) {
            alert("没有信息。");
        }
        else {
            AreaName = data.msg.areaName;
            cityId = data.msg.cityId;
        }
    })
    $("#txtStartCityName").val(AreaName);
    $("#hscity").val(cityId);
    $("#txtStartCityName").attr("tips", AreaName);
    $("#hsdepth").val(2);
}

function fun_displayObj(objId, entity, n, num) {
    var s = objId.offset();
    $('#' + entity).css({ top: s.top - n, left: s.left - num }).show();
}
function fillOption(name, id, depth) {
    var arr = name.split(">"), rid;
    name = arr.length == 1 ? $.trim(arr[0]) : $.trim(arr[1]);
    if (!isNaN(id)) {
        rid = parseInt(id);
        rid = rid == 13 ? 1020 : rid;
        rid = rid == 14 ? 1024 : rid;
        rid = rid == 101 ? 1022 : rid;
        rid = rid == 241 ? 1026 : rid;
    }
    else {
        rid = id;
    }
    nobj.attr("value", name);
    iobj.attr("value", rid);
    dobj.attr("value", depth);
    dclick();
}

function fillSelectOnkeyup(svalue, i, j, evt) {
    if ($.trim(svalue) != '') {
        var hotobj = $('li.onhover').length == 1 ? $('li.onhover').attr('id') : "";
        var num = $('li[id^=suggest_]').length;
        if (hotobj != "") {
            var arr = hotobj.split('_');
            hotnum = parseInt(arr[1]);
        }
        if (evt.keyCode == 40) {
            if (num > 0 && !$('#hotcityhintDiv').is(':hidden')) {
                if (hotobj == "") {
                    $('#suggest_0').addClass("onhover");
                }
                else {
                    var nextobj = "suggest_" + (hotnum == num - 1 ? 0 : hotnum + 1);
                    $('#' + hotobj).removeClass("onhover");
                    $('#' + nextobj).addClass("onhover");
                }
            }
        }
        else if (evt.keyCode == 38) {
            if (num > 0 && !$('#hotcityhintDiv').is(':hidden')) {
                if (hotobj == "") {
                    $('#suggest_' + (num - 1)).css("onhover");
                }
                else {
                    var preobj = "suggest_" + (hotnum == 0 ? num - 1 : hotnum - 1);
                    $('#' + hotobj).removeClass("onhover");
                    $('#' + preobj).addClass("onhover");
                }
            }
        }
        else if (evt.keyCode != 9 && evt.keyCode != 27) {
            if (evt.keyCode == 13 || evt.keyCode == 108) {
                if (!$('#hotcityhintDiv').is(':hidden')) {
                    fillOption($('#suggest_' + hotnum).attr('title'), $('#suggest_' + hotnum).attr('deffer'), $('#suggest_' + hotnum).attr('depth'));
                }
            }
            else if (evt.keyCode == 8 || evt.keyCode == 32 || evt.keyCode == 46 || (evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 65 && evt.keyCode <= 90) || (evt.keyCode >= 96 && evt.keyCode <= 105)) {
                fillSelect(svalue, i, j, evt);
            }
            else {
                $('#scity').html("<li class=\"error\">输入错误</li>");
                fun_displayObj(nobj, 'hotcityhintDiv', -20, 0);
            }
        }
    }
    else {
        $('#hotcityhintDiv').hide();
        iobj.attr("value", "");
    }
    return false;
}
function fillSelect(svalue, i, j, evt) {
    $('#scity').html("");
    iobj.attr("value", "");
    svalue = svalue.toLowerCase();
    var arr, s;
    switch (tt) {
        case 'citys':
            fillstartcity(0, 2, svalue, 7);
            break;
        case 'citye':
            fillendcity(0, 2, svalue, 7);
            break;
        case 'all':
            fillLine(3, 5, svalue, 7);
            break;
        case 'scenic':
            fillLine(0, 3, svalue, 7);
            break;
        case 'airs':
            fillflight(svalue, i, 0);
            break;
        case 'aire':
            fillflight(svalue, i, 1);
            break;
        case 'hotel':
            fillHotel(1, 4, svalue, 7);
            break;
        case 'djMdd':
            fillDjMdd(svalue);
            break;
    }
}



function fillHotel(i, j, svalue, k) {

    $.getJSON('http://beijing.lotour.com/hotel/api/AssociateRegion?i=' + i + '&j=' + j + '&key=' + escape(svalue) + (tt == 'citye' ? '&l=1' : '') + '&k=' + k + '&callback=?',
        function (data) {
            if (data.status) {
                if (data.msg.length == 0) {
                    $('#scity').html("<li class=\"error\">输入错误</li>");
                }
                else {

                    var html = '';

                    $('#scity').empty();
                    for (var l = 0; l < data.msg.length; l++) {
                        html += '<li ' + (l == 0 ? " class=\"onhover\"" : "") + '  id=\"suggest_' + l + '\"  title=\"' + data.msg[l].name + '\" deffer=\"' + data.msg[l].id + '\" depth=\"' + data.msg[l].depth + '\"><div>';
                        if (data.msg[l].depth > 6) {
                            html += '<div class=\"fl\">' + data.msg[l].name + '</div> <div class=\'fr\'>' + data.msg[l].type + '</div>';
                        }
                        else {
                            html += data.msg[l].name;
                        }
                        html += '</div></li>';
                    }
                    $(html).appendTo('#scity');
                }
                fun_displayObj(nobj, "hotcityhintDiv", -20, 0);
                return false;
            }
            else {
                $('#scity').html("<li class=\"error\">输入错误</li>");
            }
        });
}

//线路出发城市联想
function fillstartcity(i, j, svalue, k) {
    $.getJSON('http://beijing.lotour.com/dujiaxianlu/api-AssociateSSiteRegion?i=1&j=4&key=' + escape(svalue) + '&k=7&callback=?',
        function (data) {
            if (data.status) {
                if (data.msg.length == 0) {
                    $('#scity').html("<li class=\"error\">输入错误</li>");
                }
                else {
                    $('#scity').empty();
                    for (var l = 0; l < data.msg.length; l++) {
                        $("<li " + (l == 0 ? " class=\"onhover\"" : "") + " id=\"suggest_" + l + "\" title=\"" + data.msg[l].name + "\" deffer=\"" + data.msg[l].id + "\" depth=\"" + data.msg[l].depth + "\">" + data.msg[l].name + "</li>").appendTo('#scity');
                    }
                }
                fun_displayObj(nobj, "hotcityhintDiv", -19, 6);
                return false;
            }
            else {
                $('#scity').html("<li class=\"error\">输入错误</li>");
            }
        });
}


//线路目的地城市联想
function fillendcity(i, j, svalue, k) {
    $.getJSON('http://beijing.lotour.com/dujiaxianlu/api-AssociateOSiteRegion?i=0&j=4&key=' + escape(svalue) + '&k=7&callback=?',
        function (data) {
            if (data.status) {
                if (data.msg.length == 0) {
                    $('#scity').html("<li class=\"error\">输入错误</li>");
                }
                else {
                    $('#scity').empty();
                    for (var l = 0; l < data.msg.length; l++) {
                        $("<li " + (l == 0 ? " class=\"onhover\"" : "") + " id=\"suggest_" + l + "\" title=\"" + data.msg[l].name + "\" deffer=\"" + data.msg[l].id + "\" depth=\"" + data.msg[l].depth + "\">" + data.msg[l].name + "</li>").appendTo('#scity');
                    }
                }
                fun_displayObj(nobj, "hotcityhintDiv", -19, 6);
                return false;
            }
            else {
                $('#scity').html("<li class=\"error\">输入错误</li>");
            }
        });
}


//地接线路目的地【城市|景区】联想
function fillDjMdd(svalue) {
    $.getJSON('http://beijing.lotour.com/dijiexianlu/api-AssociateRegion?key=' + escape(svalue) + '&callback=?',
        function (data) {
            if (data.status) {
                if (data.msg.length == 0) {
                    $('#scity').html("<li class=\"error\">输入错误</li>");
                }
                else {
                    $('#scity').empty();
                    for (var l = 0; l < data.msg.length; l++) {
                        $("<li " + (l == 0 ? " class=\"onhover\"" : "") + " id=\"suggest_" + l + "\" title=\"" + data.msg[l].name + "\" deffer=\"" + data.msg[l].id + "\">" + data.msg[l].showname + "</li>").appendTo('#scity');
                    }
                }
                fun_displayObj(nobj, "hotcityhintDiv", -19, 6);
                return false;
            }
            else {
                $('#scity').html("<li class=\"error\">输入错误</li>");
            }
        });
}

function fillLine(i, j, svalue, k) {
    $.getJSON('http://search.lotour.com/searchbox/LineSearch.ashx?i=' + i + '&j=' + j + '&key=' + escape(svalue) + (tt == 'citye' ? '&l=1' : '') + '&k=' + k + '&callback=?',
        function (data) {
            if (data.status) {
                if (data.msg.length == 0) {
                    $('#scity').html("<li class=\"error\">输入错误</li>");
                }
                else {
                    $('#scity').empty();
                    for (var l = 0; l < data.msg.length; l++) {
                        $("<li " + (l == 0 ? " class=\"onhover\"" : "") + " id=\"suggest_" + l + "\" title=\"" + data.msg[l].name + "\" deffer=\"" + data.msg[l].id + "\" depth=\"" + data.msg[l].depth + "\">" + data.msg[l].name + "</li>").appendTo('#scity');
                    }
                }
                fun_displayObj(nobj, "hotcityhintDiv", -20, 0);
                return false;
            }
        });
}
function fillflight(svalue, i, j) {
    $.getJSON('http://search.lotour.com/searchbox/flightsearch.ashx?key=' + escape(svalue) + '&i=' + i + '&j=' + j + '&callback=?',
      function (data) {
          if (data.status) {
              if (data.msg.length == 0) {
                  $('#scity').html("<li class=\"error\">输入错误</li>");
              }
              else {
                  $('#scity').empty();
                  for (var k = 0; k < data.msg.length; k++) {
                      if (data.msg[k].nname != '') {
                          if (!(k > 0 && data.msg[k].name == data.msg[k - 1].name)) {
                              $("<li class=\"nearbyAirport\" title=\"" + data.msg[k].nname + "\">" + regSelect(data.msg[k].name, svalue) + (data.msg[k].code != '' ? "(" + regSelect(data.msg[k].code, svalue) + ")" : "") + "-该城市没有机场</li>").appendTo('#scity');
                          }
                          $("<li id=\"suggest_" + k + "\" deffer=\"" + data.msg[k].cod + "\" depth=\"" + data.msg[k].depth + "\" title=\"" + data.msg[k].nname + "\"  " + (k == 0 ? " class=\"onhover\"" : "") + ">·临近机场:" + data.msg[k].nname + "-" + data.msg[k].distince + "公里</li>").appendTo('#scity');
                      }
                      else {
                          t = 0;
                          $("<li " + (k == 0 ? " class=\"onhover\"" : "") + " id=\"suggest_" + k + "\" depth=\"" + data.msg[k].depth + "\" deffer=\"" + data.msg[k].cod + "\" title=\"" + data.msg[k].name + "\">" + regSelect(data.msg[k].name, svalue) + "(" + regSelect(data.msg[k].code, svalue) + ")</li>").appendTo('#scity');
                      }
                  }
              }
              fun_displayObj(nobj, "hotcityhintDiv", -20, 0);
              return false;
          }
      });
}
function regSelect(s0, s1) {
    return s0.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + s1.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<span class=\"keystring\">$1</span>");
}
function isDateString(str) {
    var reg = /^\d{4}-[0-1]?\d{1}-[0-3]?\d{1}$/;
    return reg.test(str);
}

function showCal(firstObjGetDate_, secondObjGetDate_, isAllowSelectFlag, objcompareStareDate, num, n) {
    var objGetDate;
    var cf = $("#CalFrame");
    var wcf = window.frames.CalFrame;
    if (!firstObjGetDate_) {
        alert("╭──────────╮\nㄧ  输入控件未指定！  ㄧ\n╰──────────╯");
        $('#CalFrame').hide();
        return;
    }
    objGetDate = $('#' + firstObjGetDate_);
    if (objGetDate.length == 0) {
        alert("输入控件不存在！");
        $('#CalFrame').hide();
        return;
    }

    if (!wcf.bCalLoaded) {
        alert("日历未成功装载！请刷新页面！o");
        $('#CalFrame').hide();
        return;
    }
    wcf.n_textdate = secondObjGetDate_;
    wcf.$isAllowSelectExpireDate = isAllowSelectFlag;
    wcf.firstObjGetDate = firstObjGetDate_;
    var startDateValue = $.trim(objcompareStareDate) == "" ? false : $('#' + objcompareStareDate).attr('value');
    if (startDateValue) {
        var dateValueStartArray = new Array(3);
        if (isDateString(startDateValue)) {
            dateValueStartArray = startDateValue.toString().split("-");
            year = parseFloat(dateValueStartArray[0]);
            month = parseFloat(dateValueStartArray[1]) - 1;
            day = parseFloat(dateValueStartArray[2]);
            dateValueStart = new Date(year, month, day);
        }
        else {
            dateValueStart = "";
        }
    }
    else {
        dateValueStart = "";
    }
    wcf.valueCompareStareDate = dateValueStart;
    $('#CalFrame').hide();
    wcf.objGetDate = objGetDate;
    if (secondObjGetDate_.length > 0) {
        objNextGetDate = $('#' + secondObjGetDate_)
        if (objNextGetDate.length > 0) { wcf.objNextGetDate = objNextGetDate; }
    }
    wcf.initCalendar();
    fun_displayObj($("#" + firstObjGetDate_), "CalFrame", n, num);
}
function hideoptios(id) {
    $('#' + id).hide();
}
function getNextD(obj) {
    return $("input[method=" + obj.attr('id') + "]").attr("id");
}
function checkForm() {
    oi = parseInt(oi);
    var testdate = /^\d{4}(-)\d{1,2}(-)\d{1,2}$/;
    switch (oi) {
        case 1:
            if ($.trim($("#keys").attr("value")) == '') {
                $("#keyword").focus();
                alert('目的地错误');
                return false;
            }
            break;
        case 2:
            if ($.trim($('#hidsight').attr('value')) == '') {
                $('#txtsight').focus();
                alert('目的地错误');
                return false;
            }
            break;
        case 3:

            var str = new Array();
            var osite = $.trim($("#hidhRegion").val());
            str = osite.split(',');
            if (str[0] == '') {
                alert('请选择您要查询的城市!');
                return false;
            }
            var sdate = $("#txthSdate").val();
            var edate = $("#txthEdate").val();
            if ($.trim($('#txthSdate').attr('value')) == '' || !testdate.test($.trim($('#txthSdate').attr('value')))) {
                $('#txthSdate').focus();
                return false;
            }
            if ($.trim($('#txthEdate').attr('value')) == '' || !testdate.test($.trim($('#txthEdate').attr('value')))) {
                $('#txthEdate').focus();
                return false;
            }
            var date1 = $('#txthSdate').attr('value').split(/-|\/|\s/);
            var date2 = $('#txthEdate').attr('value').split(/-|\/|\s/);

            var myDate1 = new Date(date1[0], date1[1] - 1, date1[2]);
            var myDate2 = new Date(date2[0], date2[1] - 1, date2[2]);
            if (myDate1 > myDate2) {
                alert('离店日期必须大于或等于入住日期');
                return false;
            }
            var cityname = "http://" + str[0] + ".lotour.com/hotel";
            var countyname = str[1] == "" ? "" : "/" + $.trim(str[1]);
            var type = str[3];
            var sightname = str[2] == "" ? "" : (type > 4 ? "-" : "_") + $.trim(str[2]);
            window.location.href = cityname + countyname + sightname + "?sdate=" + sdate + "&edate=" + edate;
            return false;


            break;
        case 4:
            if ($.trim($('#hscity').attr('value')) == '') {
                alert('请选择出发地！');
                $('#txtStartCityName').focus();
                return false;
            }
            if ($.trim($('#hecity').attr('value')) == '') {
                alert('请选择目的地！');
                $('#txtEndCityName').focus();
                return false;
            }
            break;
        case 5:
            var isForeign = $.trim($("#dbord").attr("value")) == "1" ? true : false;
            if (isForeign) {
                $('#Dtype').attr('value', 'A');
                $('#Dstartcityname').attr('name', 'Astartcityname');
                $('#DStartCityCode').attr('name', 'AStartCityCode');
                $('#DEndCityName').attr('name', 'AEndCityName');
                $('#DEndCityCode').attr('name', 'AEndCityCode');
                $('#DStartDate').attr('name', 'AStartDate');
                $('#DAddressName').attr('name', 'AAddressName');
                $('#DAddressCode').attr('name', 'AAddressCode');
            }
            else {
                $('#Dtype').attr('value', 'D');
                $('#Dstartcityname').attr('name', 'Dstartcityname');
                $('#DStartCityCode').attr('name', 'DStartCityCode');
                $('#DEndCityName').attr('name', 'DEndCityName');
                $('#DEndCityCode').attr('name', 'DEndCityCode');
                $('#DStartDate').attr('name', 'DStartDate');
                $('#DAddressName').attr('name', 'DAddressName');
                $('#DAddressCode').attr('name', 'DAddressCode');
            }
            if ($.trim($('#DStartCityCode').attr('value')) == '') {
                $('#Dstartcityname').focus();
                alert('出发地错误');
                return false;
            }
            if ($.trim($('#DEndCityCode').attr('value')) == '') {
                $('#DEndCityName').focus();
                alert('目的地错误');
                return false;
            }
            if ($('#Dstartcityname').attr('value') == $('#DEndCityName').attr('value')) {
                alert('出发地和目的地不能相同');
                return false;
            }
            if ($.trim($('#DStartDate').attr('value')) == '' || !testdate.test($.trim($('#DStartDate').attr('value')))) {
                $('#DStartDate').focus();
                return false;
            }
            $('#DAddressName').attr('value', $.trim($('#Dstartcityname').attr('value')));
            $('#DAddressCode').attr('value', $.trim($('#DStartCityCode').attr('value')));
            break;
        case 8:
            if ($.trim($('#hidregion').val()) == '') {
                alert('请选择目的地！');
                $('#txthMddRegion').focus();
                return false;
            }
            break;
    }
    return true;
}
function showdate(n) {

    var uom = new Date(new Date() - 0 + n * 86400000);
    var m = uom.getMonth() + 1;
    var d = uom.getDate();
    uom = uom.getFullYear() + "-" + (m > 9 ? m : "0" + m) + "-" + (d > 9 ? d : "0" + d);
    return uom;
}

function setToday(obj) {
    var date = new Date();
    var year = date.getYear();
    if (parseInt(year) - 1900 < 0) {
        year = year + 1900;
    }
    var str = year + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    jQuery(obj).val(str);
}